package com.cheney.mapboxexample.mapbox;

import java.util.ArrayList;
import java.util.List;

public class MapGeoJsonUtil {

    public static MapGeoJson getMapGeoJsonFromList(List<PhotoAnnotation> list) {
        if (list == null || list.size() <= 0){
            return null;
        }
        MapGeoJson mapGeoJson = new MapGeoJson();
        List<MapGeoJson.FeaturesBean> featureList = new ArrayList<>();
        //填充数据
        for (PhotoAnnotation photoAnnotation : list) {
            MapGeoJson.FeaturesBean fBean = new MapGeoJson.FeaturesBean();
            fBean.setProperties(getDevicePropertiesBeanX(photoAnnotation.getId(), photoAnnotation.getImageName()));
            fBean.setGeometry(getGeometryBean(photoAnnotation.getLatitude(), photoAnnotation.getLongitude()));
            featureList.add(fBean);
        }
        mapGeoJson.setFeatures(featureList);
        return mapGeoJson;
    }

    private static MapGeoJson.FeaturesBean.FeatureGeometry getGeometryBean(double latitude, double longitude) {
        MapGeoJson.FeaturesBean.FeatureGeometry geometryBean = new MapGeoJson.FeaturesBean.FeatureGeometry();
        List<Double> coordinates = new ArrayList<>();
        coordinates.add(longitude);
        coordinates.add(latitude);
        geometryBean.setCoordinates(coordinates);
        return geometryBean;
    }

    private static MapGeoJson.FeaturesBean.FeatureProperties getDevicePropertiesBeanX(String id, String imageName) {
        MapGeoJson.FeaturesBean.FeatureProperties pBeanX = new MapGeoJson.FeaturesBean.FeatureProperties();
        pBeanX.setId(id);
        pBeanX.setImageName(imageName);
        return pBeanX;
    }
}
